<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%system_auth_relation}}`.
 */
class m230831_102035_create_system_auth_relation_table extends Migration
{
    const TABLE_NAME = '{{%system_auth_relation}}';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ENGINE=InnoDB COMMENT="系统权限关联表"';
        }

        $this->createTable(self::TABLE_NAME, [
            'group_id' => $this->integer()->notNull()->comment('系统用户组ID'),
            'menu_id' => $this->integer()->notNull()->comment('系统菜单ID'),
            'created_at' => $this->dateTime()->notNull(),
        ], $tableOptions);

        $this->addPrimaryKey('mixed_primary_key', self::TABLE_NAME, ['group_id', 'menu_id']);
        $this->createIndex('idx_menu_id', self::TABLE_NAME, ['menu_id']);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable(self::TABLE_NAME);
    }
}
